package vip.meeet.helper;

import com.alibaba.fastjson.JSONObject;
import vip.meeet.bean.echarts.AxisType;
import vip.meeet.bean.echarts.ChartType;
import vip.meeet.bean.echarts.EData;
import vip.meeet.bean.echarts.Indicator;

import java.util.Arrays;
import java.util.List;

public class EchartsHelper {

    /**
     * 折线图
     * @param title 标题
     * @param legend 图例
     * @param x x轴配置
     * @param y y轴配置
     * @param series 数据
     * @return
     */
    public static JSONObject buildLineResult(String title, List<String> legend, List<EData> x, List<EData> y, List<EData> series){
        JSONObject result = new JSONObject();
        result.put("title",title);
        result.put("legend",legend);
        result.put("xAxis",x);
        result.put("yAxis",y);
        result.put("series",series);
        return result;
    }

    public static JSONObject buildLineResult(String title, List<String> legend, EData x, EData y, List<EData> series){
        return buildLineResult(title,legend, Arrays.asList(x),Arrays.asList(y),series);
    }

    public static JSONObject buildLineResult(String title, List<String> legend, EData x, EData y, EData series){
        return buildLineResult(title,legend, x,y,Arrays.asList(series));
    }

    public static JSONObject buildPieResult(String title, List<String> legend, List<EData> series){
        JSONObject result = new JSONObject();
        result.put("title",title);
        result.put("legend",legend);
        result.put("series",series);
        return result;
    }

    public static JSONObject buildPieResult(String title, List<String> legend, EData serie){
        return buildPieResult(title, legend, Arrays.asList(serie));
    }

    public static JSONObject buildRadarResult(String title, List<String> legend, List<Indicator> indicator, List<EData> series){
        JSONObject result = new JSONObject();
        result.put("title",title);
        result.put("legend",legend);
        result.put("indicator",indicator);
        result.put("series",series);
        return result;
    }

    public static JSONObject buildRadarResult(String title, List<String> legend, List<Indicator> indicator, EData serie){
        return buildRadarResult(title, legend, indicator, Arrays.asList(serie));
    }

    public static EData buildY(AxisType type,String name){
        EData<Object> y = new EData<>();
        y.setType(type.getType());
        y.setName(name);
        return y;
    }

    public static <T> EData buildX(AxisType type,List<T> data){
        EData<T> x = new EData<>();
        x.setData(data);
        x.setType(type.getType());
        return x;
    }

    public static <T> EData buildSerie(ChartType type, String name,List<T> data){
        EData<T> serie = new EData<>();
        serie.setType(type.getType());
        serie.setName(name);
        serie.setData(data);
        return serie;
    }
}
